define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'upgradeorder/index' + location.search,
                    add_url: 'upgradeorder/add',
                    // edit_url: 'upgradeorder/edit',
                    del_url: 'upgradeorder/del',
                    multi_url: 'upgradeorder/multi',
                    import_url: 'upgradeorder/import',
                    table: 'expert_upgrade_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        //,1：团长,2：家庭酒庄,3：区县代理
                        {field: 'upgrade_type', title: __('Upgrade_type'), searchList: { 0: '其他',1: '团长', 2: '家庭酒庄', 3: '区县代理商' },formatter:Table.api.formatter.normal},
                        {field: 'user_id', title: __('User_id')},{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE',searchable: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'all_money', title: __('All_money'), operate:'BETWEEN'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
